<?php

require_once 'BaseHelper.class.php';

class AdminHelper extends BaseHelper {
	
	public static $MODULE_NAME = "Admin"; //数据库操作的模块名

	//------------------------------------基本函数开始----------------------------------------
	public static function add($data,$displaySQL = false) {
		return parent::add ( self::$MODULE_NAME, $data,$displaySQL );
	}
	public static function update($data, $whereStr="",$displaySQL = false) {
		return parent::update ( self::$MODULE_NAME, $data, $whereStr,$displaySQL );
	}
	public static function updateSQL($sql,$displaySQL = false) {
		return parent::updateSQL( self::$MODULE_NAME, $sql,$displaySQL);
	}
	public static function delete($whereStr="",$displaySQL = false) {
		return parent::delete ( self::$MODULE_NAME, $whereStr ,$displaySQL);
	}
	public static function getObject($whereStr="",$displaySQL = false) {
		return parent::getObject ( self::$MODULE_NAME, $whereStr ,$displaySQL);
	}
	public static function queryObject($sql,$displaySQL = false) {
		return parent::queryObject ( self::$MODULE_NAME, $sql ,$displaySQL);
	}
	public static function queryForInt($sql,$displaySQL = false) {
		return parent::queryForInt ( self::$MODULE_NAME, $sql ,$displaySQL);
	}
	public static function getList($whereStr = '', $orderStr = '', $limitNum = 0,$displaySQL = false) {
		return parent::getList ( self::$MODULE_NAME, $whereStr, $orderStr, $limitNum ,$displaySQL);
	}
	public static function queryList($sql = '', $displaySQL = false) {
		return parent::queryList(self::$MODULE_NAME,$sql,$displaySQL);
	}
	//------------------------------------基本函数结束----------------------------------------


	//------------------------------------自定义函数开始--------------------------------------
	
	//检测登录信息[成功：保存用户信息 In Session]，[失败：返回信息]
	public static function checkLogin($adminName, $password) {
		$admin = self::getObject("admin_name='$adminName'");
		if($admin == null || $admin == false){
			return "用户名不存在！";
		}
		$salt = $admin ['salt'];
		if ($admin['admin_pwd'] == md5($password."_".$salt)) { //用户验证成功
			session('admin', $admin);
			return "true";
		} else {
			return "密码不正确！";
		}
	}
	
	/*
	 * 修改管理员密码
	 */
	public static function updatePWD($adminName, $newpwd,$salt) {
		$model = M("Admin");
		$data['admin_pwd'] = md5($newpwd."_".$salt);
		$data['salt'] = $salt;
		$result = $model->where("admin_name='$adminName'")->save($data);
		return $result;
	}
	
	//------------------------------------自定义函数结束--------------------------------------


}